﻿using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using OpenChart.Entities;
using System.Drawing.Drawing2D;

using OpenChart.PublicUnits;

namespace OpenChart.DrawChart
{
    class DrawingAreaChart:DrawingLineChart
    {
        /// <summary>
        /// 绘制数据
        /// </summary>
        protected override void DrawData()
        {
            base.DrawData();
        }

        /// <summary>
        /// 绘制Series
        /// </summary>
        /// <param name="item">Series</param>
        protected override void DrawSeries(Series item)
        {
            Brush brush = new SolidBrush(Color.FromArgb(128, item.Color));
            List<PointF> points = new List<PointF>();
            for (int i = 0; i < this.ChartArea.Data.Rows.Count; i++)
            {
                double xValue = ChartHelper.GetDoubleValue(this.ChartArea.Data.Rows[i][this.ChartArea.XValueMember], this.ChartArea.AxisX.IntervalType);
                if (xValue < _minXValue || xValue > _maxXValue)
                {
                    continue;
                }
                double yValue = ChartHelper.GetDoubleValue(this.ChartArea.Data.Rows[i][item.YValueMember], this.ChartArea.AxisY1.IntervalType);
                if (yValue < _minYValue || yValue > _maxYValue)
                {
                    continue;
                }
                points.Add(this.GetPoint(xValue, yValue));
            }
            if (points.Count > 0)
            {
                points.Add(new PointF(points.Last().X, this.CanvasHeight - CON_DOWN_RANGE));
                points.Add(new PointF(CON_LEFT_RANGE, this.CanvasHeight - CON_DOWN_RANGE));
                GraphicsPath path = new GraphicsPath();
                path.AddLines(points.ToArray());
                this.Graphics.FillPath(brush, path);
            }
        }
    }
}
